 package Turma.Jogo;

import Turma.Jogo.SceneManager.CENA;
import android.framework.Game;
import android.framework.Graphics.PixmapFormat;

public class Level02Arkanoid extends Scene
{
	Background background;
	ArkanoidBall ball;
	PlayerArkanoid playerArkanoid;
	int Iniciar;
	
	Game game;
	GameObject vida;
	
	final int NUM_COL = 15;
	final int NUM_LINE = 2;
	
	public Level02Arkanoid(Game game)
	{
		super(game);
		this.game = game;
		background = new Background(game.getGraphics(), "background.png", PixmapFormat.ARGB4444, 0, 0);
		
		ball = new ArkanoidBall(game.getGraphics().getWidth() / 2, game.getGraphics().getHeight() / 2, 20, 20, 6, -10, game);
		playerArkanoid = new PlayerArkanoid(game.getGraphics().getWidth() / 2, 440, 100, 10, game);
		
		RectManager.Setup(game.getGraphics(), NUM_COL, NUM_LINE, 2);
		SceneManager.currentScene = SceneManager.CENA.SCN_Level01Arkanoid;
		
		vida = new Background(game.getGraphics(), "vida.png", PixmapFormat.ARGB4444, 0, 0);
		vida.y = game.getGraphics().getHeight() - vida.image.getHeight();
		GameData.vidas = 3;
	}	

	@Override
	public void update(float deltaTime) 
	{
		if(Iniciar < 30)
		{
			Iniciar++;
		}
		else
		{
			RectManager.update(ball, deltaTime);
			playerArkanoid.update(deltaTime);
			
			if(ball.y > game.getGraphics().getHeight())
			{
				ball.x = game.getGraphics().getWidth() / 2 - ball.image.getWidth() / 2;
				ball.y = game.getGraphics().getHeight() / 2 - ball.image.getHeight() / 2;
				
				GameData.vidas -= 1;
				if(GameData.vidas < 0)
				{
					SceneManager.currentScene = CENA.SCN_GameOver;
					SceneManager.MudarCena();
				}
			}
			
			if(playerArkanoid.Collision(ball))
			{
				ball.speedy*= -1;
			}
			
			if (RectManager.recs.size() <= 0)
        	{
            	SceneManager.MudarCena();
        	}
		
			ball.Update();
		}
	}

	@Override
	public void draw(float deltaTime) 
	{
		background.draw(deltaTime, game.getGraphics());
		
		for(int contador = 0; contador < GameData.vidas; contador++)
		{
			vida.x = vida.image.getWidth() * contador;
			vida.draw(deltaTime, graphics);
		}
		
		RectManager.draw(game.getGraphics(), deltaTime);
		ball.draw(deltaTime, game.getGraphics());
		playerArkanoid.draw(deltaTime, game.getGraphics());
	}

	@Override
	public void pause() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub
		
	}
}
